<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态组件</title>
    <script src="https://cdn.bootcss.com/vue/2.6.11/vue.js"></script>
    <script src="js/jquery.js"></script>
    <script>
        $(function(){
            var vm1 = new Vue({
                el:'#mydiv',
                data:{
                    comType:'com1'
                },
                components:{
                    'com1':{
                        template:'#mytemp1'
                    },
                    'com2':{
                        template:'#mytemp2'
                    }
                }
            })
        })
    </script>
</head>
<body>
    <template id="mytemp1">
        <div>
            <h2>这是我的局部组件A</h2>
        </div>
    </template>
    <template id="mytemp2">
        <div>
            <h2>这是我的局部组件B</h2>
        </div>
    </template>
    <div id="mydiv">
        <!-- <com1></com1>
        <com2></com2> -->
        <button @click="comType='com1'">显示组件A</button>
        <button @click="comType='com2'">显示组件B</button>
        <component :is='comType'></component>
    </div>
</body>
</html>